index_app.controller("inventory_settings_list", function ($scope,$http) {

	var grid_selector = "#grid-table";
	var pager_selector = "#grid-pager";


	$(window).on('resize.jqGrid', function() {
		$(grid_selector).jqGrid('setGridWidth', $(".page-content").width());
	});

	jQuery(grid_selector).jqGrid('aceInit', pager_selector, {
		url:"commodityDetailed/listDetailed",
		datatype : "json",
		colNames : ['','ID', '商品编号','商品名称','商品单价','所属类别','库存', '管理操作'],
		colModel : [
		           {name:'myac',hidden:true},
		           {name:'detailedKey',index:'detailedKey', width:60,hidden:true},
		           {name:'sku',index:'sku', width:60},
		           {name:'name',index:'name', width:60},
		           {name:'price',index:'price', width:60},
		           {name:'skuType.skuType',index:'skuType', width:60},
		           {name:'stock',index:'stock', width:60},
		           {name:'detailedKey',index:'detailedKey',
                   		  width:60, sorttype:"integer",
                   		    formatter: function(value,row,index){
                   		        return "<a style='cursor:pointer' onclick='outGoing("+index.detailedKey+")'>出库</a> || <a style='cursor:pointer' onclick='storage("+index.detailedKey+")'>入库</a>";
                   		    }
                   	}
		            ],
		            sortable:true,
		            sortname:'detailedKey',
		            sortorder:'asc',
		            caption : "<i class='menu-icon fa fa-pencil white'></i> 库存设置"
	});
	jQuery(grid_selector).jqGrid('aceNavGrid', pager_selector);
    	//查找事件
        $scope.searchByName = function(){
            $(grid_selector).jqGrid('setGridParam',{
                  url:"commodityDetailed/searchSelf?field=Name&fieldValue="+$("#skuName").val(),
                  datatype:'json',
                   page:1
            }).trigger("reloadGrid");
        }
    $scope.refresh = function(){
    $("#skuName").val("");
        $(grid_selector).jqGrid('setGridParam',{
                          url:"commodityDetailed/listDetailed",
                          datatype:'json',
                           page:1
                    }).trigger("reloadGrid");
    }

})

function outGoing(key){
	   window.location.href="#inventory_settings_edit/"+key+"/outGoing";
}

function storage(key){
     window.location.href="#inventory_settings_edit/"+key+"/storage";
}
